package com.power.controller;

import com.power.domain.Area;
import com.power.model.Result;
import com.power.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description 地区业务模块控制层
 * @Author dingchunlin
 * @Date 2024/07/16 15:36
 * @Version 1.0.0
 */
@Api(tags = "地区业务模块控制层")
@RequestMapping("/admin/area")
@RestController
public class AreaController {

    @Autowired
    private AreaService areaService;

    /**
     * 获取所有地区列表
     * @return  Result<List<Area>>
     */
    @ApiOperation(value = "查询全国地区列表")
    @GetMapping("/list")
    @PreAuthorize("hasAnyAuthority('admin:area:list')")
    public Result<List<Area>> loadAllAreaList() {
        List<Area> areaList = areaService.queryAllAreaList();
        return Result.success(areaList);
    }


    /**
     * 根据pid获取地区列表
     * @param pid 父级id
     * @return  Result<List<Area>>
     */
    @ApiOperation(value = "根据pid获取地区列表")
    @GetMapping("/mall/listByPid")
    public Result<List<Area>> loadAreaListByPid(@RequestParam("pid") Long pid) {
        List<Area> areaList = areaService.queryAreaListByPid(pid);
        return Result.success(areaList);
    }
}
